package order;

import logger.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-04-06
 * Time: 9:55
 */

public class OrderLogger {

    AbsFactory absFactory;

    //构造器
    public OrderLogger(AbsFactory absFactory){
        setAbsFactory(absFactory);
    }

    private void setAbsFactory(AbsFactory factory) {
        Logger logger = null;
        String type = "";
        this.absFactory = factory;
        do {
            type = getType();
            //
            logger = factory.createLogger(type);
            if (logger !=null){
                logger.instantiation();
                logger.initialization();
                logger.apply();
                logger.ruin();

            }else {
                System.out.println("订购失败");
            }
        }while (true);

    }


    //写一个方法 可以获取用户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input Logger type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }


}
